package com.jvyou.app.ds.controller;


import cn.dev33.satoken.annotation.SaCheckPermission;
import com.jvyou.app.common.domain.entity.SysSetting;
import com.jvyou.app.common.domain.model.PageResult;
import com.jvyou.app.common.domain.model.Result;
import com.jvyou.app.common.enums.HttpCodeEnum;
import com.jvyou.app.ds.domain.dto.SysSettingDto;
import com.jvyou.app.ds.service.SysSettingService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 系统设置表(SysSetting)表控制层
 *
 * @author 橘柚
 * @since 2025-03-24 10:02:50
 */
@RestController
@RequestMapping("/sysSetting")
public class SysSettingController  {
    
    @Resource
    private SysSettingService sysSettingService;

    @GetMapping("/list")
    @SaCheckPermission("sys:sysSetting:list")
    public Result<List<SysSetting>> list(@ModelAttribute SysSettingDto sysSettingDto) {
        return Result.success(sysSettingService.listSysSetting(sysSettingDto));
    }

    @GetMapping("/page")
    @SaCheckPermission("sys:sysSetting:page")
    public Result<PageResult<SysSetting>> page(@ModelAttribute SysSettingDto sysSettingDto) {
        return Result.success(sysSettingService.pageSysSetting(sysSettingDto));
    }

    /**
     * 通过主键查询单条数据
     *
     * @param id 主键
     * @return 单条数据
     */
    @GetMapping("/{id}")
    @SaCheckPermission("sys:sysSetting:get")
    public Result<SysSetting> selectOne(@PathVariable Long id) {
        return Result.success(sysSettingService.getById(id));
    }

    /**
     * 新增数据
     *
     * @param sysSetting 实体对象
     * @return 新增结果
     */
    @PostMapping
    @SaCheckPermission("sys:sysSetting:insert")
    public Result<SysSetting> insert(@RequestBody SysSetting sysSetting) {
        boolean success = sysSettingService.save(sysSetting);
        return success ? Result.success(sysSetting) : Result.error(HttpCodeEnum.ADD_FAIL);
    }
    
     /**
     * 修改数据
     *
     * @param sysSetting 实体对象
     * @return 修改结果
     */
    @PutMapping("/updateById")
    @SaCheckPermission("sys:sysSetting:update")
    public Result<SysSetting> updateById(@RequestBody SysSetting sysSetting) {
        boolean success = sysSettingService.updateById(sysSetting);
        return success ? Result.success(sysSetting) : Result.error(HttpCodeEnum.UPDATE_FAIL);
    }
    

    /**
     * 删除数据
     *
     * @param id 主键结合
     * @return 删除结果
     */
    @DeleteMapping("/{id}")
    @SaCheckPermission("sys:sysSetting:delete")
    public Result<Boolean> delete(@PathVariable Long id) {
        boolean success = sysSettingService.removeById(id);
        return success ? Result.success(true) : Result.error(HttpCodeEnum.DELETE_FAIL);
    }
    
}

